package com.ndp.fb.rdb.db.impl.mapper;

import com.ndp.fb.rdb.db.JdbcTemplateMixed;
import com.ndp.fb.rdb.model.VpiCountryInfo;
import com.ndp.fb.rdb.model.VpiInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by Mikey.zhaopeng on 2015/3/18 17:52.
 * Email mikey.zhao@ndpmedia.com
 */

@Component
public class VpiInfoRowMapper implements RowMapper<VpiInfo> {
    @Autowired
    private JdbcTemplateMixed jdbcTemplate;

    @Override
    public VpiInfo mapRow(ResultSet rs, int i) throws SQLException {
        VpiInfo vpiInfo = new VpiInfo();
        vpiInfo.setId(rs.getLong("id"));
        vpiInfo.setFbConnectionObjectId(rs.getLong("fb_connection_object_id"));
        vpiInfo.setConnectionObjectName(rs.getString("connection_object_name"));
        vpiInfo.setPlatform(rs.getString("platform"));
        vpiInfo.setUserId(rs.getString("user_id"));
        vpiInfo.setVpi(rs.getInt("vpi"));
        vpiInfo.setRemark(rs.getString("remark"));
        vpiInfo.setUpdateTime(rs.getDate("update_time"));
        vpiInfo.setCreateTime(rs.getTimestamp("create_time"));
        String sql = "SELECT * from vpi_country_info where vpi_info_id=?";
        List<VpiCountryInfo> vpiCountryInfos = this.jdbcTemplate.query(sql, DefaultRowMapper.autoRowMapper(VpiCountryInfo.class), vpiInfo.getId());
        vpiInfo.setVpiCountryInfos(vpiCountryInfos);
        return vpiInfo;
    }
}
